//
//  CYNMainViewController.swift
//  CYN微博
//
//  Created by chendada_ on 16/5/19.
//  Copyright © 2016年 chendada. All rights reserved.
//

import UIKit

class CYNMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

       addChildViewController()
    let mainTabbar  = CYNMainTabBar()
        
    setValue(mainTabbar, forKey: "tabBar")
      
    mainTabbar.plusBtn.addTarget(self, action:#selector(CYNMainViewController.plusBtnClick), forControlEvents:
        .TouchUpInside)
        
        
       
}
    
   @objc private  func plusBtnClick(){
        print("你被点击了")
    }
    
    
  private  func addChildViewController() {

//    let home = CYNHomeTableViewController()
//    home.tabBarItem.title = "首页"
//    home.tabBarItem.image = UIImage(named: "tabbar_home")
//    home.tabBarItem.selectedImage = UIImage(named: "tabbar_home_selected")
//    addChildViewController(home)
   
    addChildViewController(CYNHomeTableViewController(),title : "首页",imageName : "tabbar_home")
    
   
    addChildViewController(CYNMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
     addChildViewController(CYNDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
    addChildViewController(CYNProfileTableViewController(), title: "个人中心", imageName: "tabbar_profile")
    
    }
    
    func addChildViewController(vc:UIViewController,title:String,imageName:String) {
        //如果标签和导航条的title是一样的
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        //选中的图片 设置渲染模式
        vc.tabBarItem.selectedImage = UIImage(named: imageName+"_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置title的颜色
        //前景色
            vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        //设置title位置
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
       
        //内嵌到导航视图控制器上
        let nav = UINavigationController(rootViewController: vc)
        
        addChildViewController(nav)
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    


}
